<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Redis;

class Authentication
{
    /**
     * 接口请求鉴权
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $loginSession = $request->loginSession;
        if (!Redis::get($loginSession)){
            // 如果鉴权失败，则返回错误
            return redirect('/api/error');
        }
        return $next($request);
    }
}
